﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Ticksys_ABM_Categorias_Modificar_Categorias : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet ds = AccesoDatos.Consulta("SELECT * FROM Categorias WHERE idCategoria = '" + Request.QueryString["id"] + "'");

            BoxSector.Text = ds.Tables[0].Rows[0]["Sector"].ToString();
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        DataSet ds = AccesoDatos.Consulta("SELECT * FROM Categorias WHERE idCategoria <> '" + Request.QueryString["id"] + "' AND Categoria = '" + BoxSector.Text + "'");

        if (ds.Tables[0].Rows.Count != 0)
        {
            lbl_Error.Visible = true;
            return;
        }

        Categoria categoria = new Categoria();
        categoria.idCategoria = Request.QueryString["id"];
        categoria.categoria = BoxSector.Text;

        GuardarEnBD.ModificarCategoria(categoria);
        Response.Redirect("Categoria");
    }
}